var userinfoutil = {}, app = getApp(), util = require("../../../we7/resource/js/util.js");

userinfoutil.getOpenId = function(e) {
    var a = this;
    app.util.request({
        url: "entry/wxapp/get_userinfo",
        data: {
            code: e
        },
        success: function(e) {
            var o = e.data.data;
            if (wx.hideLoading(), console.log(e.data), null != o) {
                if (console.log("获取用户openID:" + o.openid), null != app.globalData.userInfo && "" != app.globalData.openId) wx.getStorageSync("have_status_user") && (console.log("检查一次用户信息"), 
                a.check_user_have());
                app.globalData.openId = o.openid, wx.setStorageSync("openId", o.openid);
            } else console.log("======解析失败==openid=======");
        }
    });
}, userinfoutil.getUserinfo_det = function(e) {
    var o = this, a = wx.getStorageSync("openId"), n = wx.getStorageSync("ubinfo");
    "" != a && null != a ? (app.globalData.openId = a, o.getOpenId(e)) : "" == app.globalData.openId && null != app.globalData.openId && void 0 !== n.avatarUrl && "" != n.avatarUrl ? o.getOpenId(e) : console.log("缓存App:" + app.globalData.openId), 
    "" != n && null != n ? (app.globalData.userInfo = n, console.log("缓存stroe:" + JSON.stringify(n))) : null == app.globalData.userInfo && (wx.getUserInfo({
        success: function(e) {
            var o = e.userInfo;
            console.log("实时用户信息>>>"), console.log(o), app.globalData.userInfo = o, wx.setStorageSync("ubinfo", o);
        }
    }), setTimeout(function() {
        "" == app.globalData.openId && wx.login({
            success: function(e) {
                e.code && o.getOpenId(e.code);
            }
        });
    }, 1500)), setTimeout(function() {
        null != app.globalData.userInfo && "" != app.globalData.openId && (wx.getStorageSync("have_status_user") && (console.log("检查一次用户信息"), 
        o.check_user_have()));
    }, 1200);
}, userinfoutil.getUserinfo = function() {
    var a = this;
    wx.login({
        success: function(o) {
            o.code && wx.getUserInfo({
                success: function(e) {
                    a.getUserinfo_det(o.code);
                },
                fail: function() {
                    wx.showModal({
                        title: "提示",
                        content: "授权获取用户信息失败,将不可发布消息和评论!",
                        confirmText: "去设置",
                        success: function(e) {
                            e.confirm ? wx.openSetting({
                                success: function(e) {
                                    e && (1 == e.authSetting["scope.userInfo"] ? (console.log("取得用户信息授权成功"), wx.login({
                                        success: function(e) {
                                            e.code && a.getUserinfo_det(e.code);
                                        }
                                    })) : a.getUserinfo());
                                }
                            }) : a.getUserinfo();
                        }
                    });
                }
            });
        }
    });
}, userinfoutil.check_user_have = function() {
    var e = {};
    e.u_unionid = app.globalData.unionId, e.u_openid = app.globalData.openId, e.u_nickname = app.globalData.userInfo.nickName, 
    e.u_city = app.globalData.userInfo.city, e.u_avatarurl = app.globalData.userInfo.avatarUrl, 
    e.u_gender = app.globalData.userInfo.gender, e.u_province = app.globalData.userInfo.province, 
    e.u_country = app.globalData.userInfo.country, "" != e.u_openid && app.util.request({
        url: "entry/wxapp/check_user_have",
        data: e,
        success: function(e) {
            console.log("检查用户信息:"), console.log(e.data.data), wx.setStorageSync("have_status_user", e.data.data.user_have);
        }
    });
}, userinfoutil.pay_user_account = function() {}, userinfoutil.pay_wx_api = function() {}, 
userinfoutil.gps_loc = function() {}, module.exports = userinfoutil;